﻿CREATE PROCEDURE [dbo].[ETL_SP_GetSummary4AppExtraction]
AS
	select top(5) A.AppName,
		A.AppId,
		AER2.CreatedTime,
		AER3.DataCount,
		AER3.RejectedCount,
		AER3.ExtractedCount
	from ETL_AppAuthorization as A
		inner join (
			select MAX(AER.CreatedTime) as CreatedTime,
				AER.AppId
			from ETL_AppExtractRecord as AER group by AER.AppId) as AER2 on AER2.AppId = A.AppId
		inner join ETL_AppExtractRecord as AER3 on AER3.CreatedTime = AER2.CreatedTime and AER3.AppId = A.AppId
		order by AER3.CreatedTime desc
RETURN 0
